// VBConversions Note: VB project level imports
using System.Collections.Generic;
using System;
using System.Linq;
using System.Drawing;
using System.Diagnostics;
using Microsoft.VisualBasic;
using System.Xml.Linq;
using Microsoft.VisualBasic.Compatibility;
using System.Windows.Forms;
using System.Collections;
using System.Data;
// End of VB project level imports

using System.ComponentModel;

namespace 喷码数据生成工具
{
	public class CodeEditBox : RichTextBox
	{
		const int WM_PASTE = 0x302;
		private enum EnumChangeColor
		{
			EnumKeyWordColor = 0,
			EnumClassTypeColor = 1,
			EnumErrorColor = 2,
			EnumDescriptionColor = 3,
			EnumStringTypeColor = 4
		}
		public enum EnumCodeMode
		{
			VBScript,
			JavaScript
		}
		private Color _KeyWordColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color _ClassTypeColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color _ErrorColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color _DescriptionColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private Color _StringTypeColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static.  Assignment has been moved to the class constructors.
		private int _TabCount = 4;
		private SupportWords.VbsKeyCode VbsKeyWords = new SupportWords.VbsKeyCode();
		private EnumCodeMode _CodeMode;
		public CodeEditBox()
		{
			// VBConversions Note: Non-static class variable initialization is below.  Class variables cannot be initially assigned non-static values in C#.
			_KeyWordColor = Color.FromArgb(0, 0, 255);
			_ClassTypeColor = Color.FromArgb(43, 145, 175);
			_ErrorColor = Color.Red;
			_DescriptionColor = Color.FromArgb(0, 128, 0);
			_StringTypeColor = Color.FromArgb(163, 21, 21);
			
			base.WordWrap = false;
			base.ScrollBars = RichTextBoxScrollBars.Both;
			base.AcceptsTab = true;
			LoadForamtData();
		}
[Browsable(false)][EditorBrowsable(EditorBrowsableState.Never)]public bool WordWrap
		{
			get
			{
				return base.WordWrap;
			}
			set
			{
				base.WordWrap = false;
			}
		}
public EnumCodeMode CodeMode
		{
			get
			{
				return _CodeMode;
			}
			set
			{
				_CodeMode = value;
				LoadForamtData();
				FreshString();
			}
		}
		private void LoadForamtData()
		{
			if (VbsKeyWords.FunCode != null)
			{
				VbsKeyWords.FunCode.Clear();
			}
			if (VbsKeyWords.SplitWord != null)
			{
				VbsKeyWords.SplitWord.Clear();
			}
			if (_CodeMode == EnumCodeMode.VBScript)
			{
				VbsKeyWords.AddSplitWord("Function", "End Function");
				VbsKeyWords.AddSplitWord("Private Function", "End Function");
				VbsKeyWords.AddSplitWord("Public Function", "End Function");
				VbsKeyWords.AddSplitWord("Sub", "End Sub");
				VbsKeyWords.AddSplitWord("Private Sub", "End Sub");
				VbsKeyWords.AddSplitWord("Public Sub", "End Sub");
				VbsKeyWords.AddSplitWord("With", "End With");
				VbsKeyWords.AddSplitWord("Do", "Loop");
				VbsKeyWords.AddSplitWord("While", "Wend");
				VbsKeyWords.AddSplitWord("If", "Then", "End If");
				// .AddSplitWord("For", "Next")
				VbsKeyWords.AddSplitWord("For Each", "In", "Next");
				VbsKeyWords.AddSplitWord("For Each", "As", "In", "Next");
				VbsKeyWords.AddSplitWord("For", "To", "Step", "Next");
				VbsKeyWords.AddSplitWord("For", "To", "Next");
				//日期时间函数
				VbsKeyWords.AddFunCode("CDate,Date,DateAdd,DateDiff,DatePart,DateSerial,DateValue,Day,FormatDateTime,Hour,IsDate,Minute,Month,MonthName,Now,Second,Time,Timer,TimeSerial,TimeValue,Weekday,WeekdayName,Year");
				//Conversion函数
				VbsKeyWords.AddFunCode("Asc,CBool,CByte,CCur,CDate,CDbl,Chr,CInt,CLng,CSng,CStr,Hex,Oct,Val");
				//Foramt函数
				VbsKeyWords.AddFunCode("FormatCurrency,FormatDateTime,FormatNumber,FormatPercent");
				//Math函数
				VbsKeyWords.AddFunCode("Abs,Atn,Cos,Exp,Hex,Int,Fix,Log,Oct,Rnd,Sgn,Sin,Sqr,Tan");
				//Array函数
				VbsKeyWords.AddFunCode("Array,Filter,IsArray,Join,Lbound,Split,UBound,Mod");
				//String函数
				VbsKeyWords.AddFunCode("InStr,InStrRev,LCase,Left,Len,LTrim,Trim,Mid,Replace,Right,Space,StrComp,String,StrReverse,UCase");
				//其他函数
				VbsKeyWords.AddFunCode("Dim,CreateObject,Eval,GetLocale,GetObject,GetRef,InputBox,IsEmpty,IsNull,IsNumeric,IsObject,LoadPicture,MsgBox,RGB,Round,ScriptEngine,ScriptEngineBuildVersion,ScriptEngineMajorVersion,ScriptEngineMinorVersion,SetLocale,TypeName,VarType,Call,Nothing,Null");
			}
			else
			{
				VbsKeyWords.AddFunCode("function,private,public,var,alert,document.getElementById,function,write,return,if,else,switch,case,default,Date,getDay");
				VbsKeyWords.AddFunCode("for,length,while,break,try,catch,throw,adddlert,with,MAX VALUE,MIN VALUE,NEGATIVE INFINITIVE,POSITIVE INFINITIVE,NaN,prototype,constructor,toExponential,toFixed,toPrecision,toString,valueOf");
				VbsKeyWords.AddFunCode("toUpperCase,getTime,setFullYear,toUTCString,In,concat,join,sort,Boolean,round,random,max,min,RegExp,exec,compile,window,innerHeight,innerWidth,clientWidth,clientHeight,body,open,close,moveTo,resizeTo");
				VbsKeyWords.AddFunCode("screen,availWidth,availHeight,location,hostname,pathname,port,portocol,href,assign,history,back,forward,navigator,confirm,prompt,setTimeout,clearTimeout,indexof,lastof,cookie");
			}
		}
		private void CheckVbsLineCode(int RowIndex, long OldSelectionStart = -1, int KeyCode = 0)
		{
			//On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C#
			string CheckString = this.Lines[RowIndex];
			int DIndex = CheckString.IndexOf("\'");
			string CheckCode = FormatSplitWordOnOneSpace(CheckString);
			long FirstIndex = this.GetFirstCharIndexFromLine(RowIndex);
			int TabC = 0;
			bool HasKeyWord = false;
			if (string.IsNullOrEmpty(CheckCode))
			{
				return ;
			}
			if (_CodeMode == EnumCodeMode.JavaScript)
			{
				DIndex = CheckString.IndexOf("//");
			}
			SupportWords.DisablePaint(this.Handle);
			if (DIndex >= 0)
			{
				this.SelectionStart = this.GetFirstCharIndexFromLine(RowIndex) + DIndex;
				this.SelectionLength = CheckString.Length - DIndex + 1;
				ChangeKeyWordColor(EnumChangeColor.EnumDescriptionColor);
				this.SelectionStart = OldSelectionStart;
				this.SelectionLength = 0;
				return ;
			}
			
			for (var i = 0; i <= VbsKeyWords.SplitWord.Count - 1; i++)
			{
				string SearchString = System.Convert.ToString(VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].StartWord1.ToLower);
				object Tag = VbsKeyWords.SplitWordTag;
				bool CanCheck = false;
				int PIndex = -1;
				if (Tag != null)
				{
					if (Conversion.Val(Tag) != i && Conversion.Val(Tag) >= 0)
					{
						CanCheck = true;
					}
				}
				if (Tag == null)
				{
					CanCheck = true;
				}
				if (CanCheck)
				{
					if (VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].WordMode == SupportWords.EnumSplitMode.NoneSplit)
					{
						PIndex = CheckCode.ToLower().IndexOf(SearchString);
						// MsgBox(PIndex)
						if (PIndex == 0)
						{
							int tmpIndex = CheckString.ToLower().IndexOf(SearchString);
							this.SelectionStart = System.Convert.ToInt32(FirstIndex + tmpIndex);
							this.SelectionLength = CheckString.Length - tmpIndex;
							this.SelectedText = CheckCode.Replace(CheckCode.Substring(0, SearchString.Length), System.Convert.ToString(VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].StartWord1));
							this.SelectionStart = System.Convert.ToInt32(FirstIndex + tmpIndex);
							this.SelectionLength = SearchString.Length;
							ChangeKeyWordColor(EnumChangeColor.EnumKeyWordColor, OldSelectionStart);
							VbsKeyWords.SplitWordTag = i;
							HasKeyWord = true;
							
						}
						else
						{
							SearchString = System.Convert.ToString(VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].EndWord.ToLower);
							PIndex = CheckCode.ToLower().IndexOf(SearchString);
							if (PIndex == 0)
							{
								int tmpIndex = CheckString.ToLower().IndexOf(SearchString);
								this.SelectionStart = System.Convert.ToInt32(FirstIndex + tmpIndex);
								this.SelectionLength = CheckString.Length - tmpIndex;
								this.SelectedText = CheckCode.Replace(CheckCode.Substring(0, SearchString.Length), System.Convert.ToString(VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].EndWord));
								this.SelectionStart = System.Convert.ToInt32(FirstIndex + tmpIndex);
								this.SelectionLength = SearchString.Length;
								ChangeKeyWordColor(EnumChangeColor.EnumKeyWordColor, OldSelectionStart);
								VbsKeyWords.SplitWordTag = i;
								HasKeyWord = true;
								// Return
							}
						}
					}
					else if (VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].WordMode == SupportWords.EnumSplitMode.SplitMode)
					{
						string SearchString1 = System.Convert.ToString(VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].StartWord1.ToLower);
						string SearchString2 = System.Convert.ToString(VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].StartWord2.ToLower);
						int Pindex1 = CheckCode.IndexOf(SearchString1);
						int Pindex2 = 0;
						if (Pindex1 == 0)
						{
							string LastString = CheckCode.Substring(Pindex1 + SearchString1.Length);
							Pindex2 = LastString.IndexOf(SearchString2);
							if (Pindex2 > 0)
							{
								string WriteString = "";
								int tmpC = getFrontSpaceCount(CheckString);
								WriteString = System.Convert.ToString(CheckCode.Replace(CheckCode.Substring(0, SearchString1.Length), System.Convert.ToString(VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].StartWord1)).Replace(CheckCode.Substring(Pindex2 + SearchString1.Length, SearchString2.Length), System.Convert.ToString(VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].StartWord2)));
								TabC = getFrontLineSpaceCount(RowIndex);
								if (TabC < 0 & tmpC <= 0)
								{
									TabC = 4;
								}
								else
								{
									TabC = tmpC < 0 ? 4 : tmpC;
								}
								this.SelectionStart = FirstIndex;
								this.SelectionLength = CheckString.Length;
								this.SelectedText = Strings.Space(TabC) + WriteString;
								this.SelectionStart = System.Convert.ToInt32(FirstIndex + TabC);
								this.SelectionLength = SearchString1.Length;
								ChangeKeyWordColor(EnumChangeColor.EnumKeyWordColor);
								this.SelectionStart = System.Convert.ToInt32(System.Convert.ToInt32(FirstIndex + TabC) + Pindex2 + SearchString1.Length);
								this.SelectionLength = SearchString2.Length;
								ChangeKeyWordColor(EnumChangeColor.EnumKeyWordColor);
								HasKeyWord = true;
							}
							else
							{
								goto CheckSplitEndWord;
							}
						}
						else
						{
CheckSplitEndWord:
							if (CheckCode.ToLower() == VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].EndWord.ToLower)
							{
								TabC = getFrontLineSpaceCount(RowIndex, System.Convert.ToString(VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].StartWord1), System.Convert.ToString(VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].EndWord));
								if (TabC < 0)
								{
									TabC = 0;
								}
								this.SelectionStart = FirstIndex;
								this.SelectionLength = CheckString.Length;
								this.SelectedText = Strings.Space(TabC) + VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].EndWord;
								this.SelectionStart = FirstIndex;
								this.SelectionLength = System.Convert.ToInt32(this.Lines[RowIndex].Length);
								ChangeKeyWordColor(EnumChangeColor.EnumKeyWordColor);
								HasKeyWord = true;
							}
						}
					}
					else if (VbsKeyWords.SplitWord[System.Convert.ToInt32(i)].WordMode == SupportWords.EnumSplitMode.ThreeSplitMode)
					{
					}
				}
			}
			if (KeyCode == 13)
			{
				this.SelectionStart = this.GetFirstCharIndexFromLine(RowIndex + 1);
				this.SelectionLength = 0;
				//Me.SelectedText = Space(TabC)
				//  Me.Parent.Text = KeyCode & RowIndex
				//Else
				//    Me.SelectionStart = OldSelectionStart
				if (HasKeyWord == false)
				{
					int tabcc = getFrontLineSpaceCount(RowIndex);
					if (tabcc < 0)
					{
						tabcc = 0;
					}
					this.SelectedText = Strings.Space(tabcc);
				}
			}
			SupportWords.AllowPaint(this.Handle);
			this.Refresh();
		}
		private void CheckInputString(int RowIndex, long OldSelectionStart)
		{
			if (RowIndex < 0 | RowIndex >= this.Lines.Count())
			{
				return ;
			}
			string tmp = this.Lines[RowIndex];
			string tmpStr1 = tmp;
			long A = 0;
			long B = 0;
			long FirstIndex = this.GetFirstCharIndexFromLine(RowIndex);
			long SIndex = tmp.IndexOf("\'");
			A = tmp.IndexOf('\u0022');
			tmpStr1 = tmp.Substring(System.Convert.ToInt32(A + 1));
			SupportWords.DisablePaint(this.Handle);
			while (!(A < 0))
			{
				try
				{
					if (A >= SIndex & SIndex > 0)
					{
						goto endOfDoLoop;
					}
					if (A + 1 > tmp.Length)
					{
						goto endOfDoLoop;
					}
					tmpStr1 = tmp.Substring(System.Convert.ToInt32(A + 1));
					B = tmpStr1.IndexOf('\u0022');
					if (B >= 0)
					{
						this.SelectionStart = System.Convert.ToInt32(A + FirstIndex);
						this.SelectionLength = System.Convert.ToInt32(B + 2);
						ChangeKeyWordColor(EnumChangeColor.EnumStringTypeColor);
						A = System.Convert.ToInt64(System.Convert.ToInt32(A + tmpStr1.Substring(System.Convert.ToInt32(B + 1)).IndexOf('\u0022')) + 2 + B);
					}
					else
					{
						goto endOfDoLoop;
					}
				}
				catch
				{
					goto endOfDoLoop;
				}
			}
endOfDoLoop:
			if (SIndex > 0)
			{
				this.SelectionStart = System.Convert.ToInt32(FirstIndex + SIndex);
			}
			this.SelectionLength = System.Convert.ToInt32(tmp.Length - SIndex);
			ChangeKeyWordColor(EnumChangeColor.EnumDescriptionColor);
			this.SelectionStart = OldSelectionStart;
			SupportWords.AllowPaint(this.Handle);
			this.Refresh();
		}
		private string FormatSplitWordOnOneSpace(string Value)
		{
			//On Error Resume Next VBConversions Warning: On Error Resume Next not supported in C#
			string[] a = Value.Split(' ');
			string Result = Constants.vbNullString;
			for (var i = 0; i <= a.Length - 1; i++)
			{
				if (!(string.IsNullOrEmpty(a[(int) i])))
				{
					if (!string.IsNullOrEmpty(Result))
					{
						Result += " " + a[(int) i];
					}
					else
					{
						Result = a[(int) i];
					}
				}
			}
			return Result;
		}
		private void ChangeKeyWordColor(EnumChangeColor ColorMode, long OldStartIndex = -1)
		{
			switch (ColorMode)
			{
				case EnumChangeColor.EnumKeyWordColor:
					this.SelectionColor = _KeyWordColor;
					break;
				case EnumChangeColor.EnumClassTypeColor:
					this.SelectionColor = _ClassTypeColor;
					break;
				case EnumChangeColor.EnumDescriptionColor:
					this.SelectionColor = _DescriptionColor;
					break;
				case EnumChangeColor.EnumErrorColor:
					this.SelectionColor = _ErrorColor;
					break;
				case EnumChangeColor.EnumStringTypeColor:
					this.SelectionColor = _StringTypeColor;
					break;
			}
			if (OldStartIndex < 0)
			{
				long SelectedStartIndex = this.SelectionStart + this.SelectionLength;
				this.SelectionStart = SelectedStartIndex;
			}
			else
			{
				this.SelectionStart = OldStartIndex;
			}
			this.SelectionColor = this.ForeColor;
			this.SelectionFont = this.Font;
		}
		private void CheckFunName(long RowIndex, long OldSelectionStart)
		{
			if (RowIndex < 0 | RowIndex > this.Lines.Count() - 1)
			{
				return ;
			}
			string tmp = this.Lines[RowIndex];
			long FirstIndex = this.GetFirstCharIndexFromLine(RowIndex);
			List<SupportWords.IsInCheckCode> CheckCode = new List<SupportWords.IsInCheckCode>();
			CheckCode.Add(new SupportWords.IsInCheckCode(48, 57));
			CheckCode.Add(new SupportWords.IsInCheckCode(65, 90));
			CheckCode.Add(new SupportWords.IsInCheckCode(97, 122));
			SupportWords.DisablePaint(this.Handle);
			try
			{
				for (var i = 0; i <= VbsKeyWords.FunCode.Count - 1; i++)
				{
					string tmpSearch = System.Convert.ToString(VbsKeyWords.FunCode[System.Convert.ToInt32(i)].FunName.ToLower);
					int Vindex = tmp.ToLower().IndexOf(tmpSearch);
					while (!(Vindex < 0 | Vindex > tmp.Length - tmpSearch.Length))
					{
						if (Vindex == 0)
						{
							this.SelectionStart = System.Convert.ToInt32(FirstIndex + Vindex);
							this.SelectionLength = System.Convert.ToInt32(VbsKeyWords.FunCode[System.Convert.ToInt32(i)].FunName.Length);
							ChangeKeyWordColor(EnumChangeColor.EnumKeyWordColor);
							this.SelectionStart = System.Convert.ToInt32(FirstIndex + Vindex);
							this.SelectionLength = System.Convert.ToInt32(VbsKeyWords.FunCode[System.Convert.ToInt32(i)].FunName.Length);
							this.SelectedText = System.Convert.ToString(VbsKeyWords.FunCode[System.Convert.ToInt32(i)].FunName);
						}
						else if (Vindex > 0 & Vindex + tmpSearch.Length < tmp.Length)
						{
							int FrontCode = Strings.Asc(tmp.Substring(Vindex - 1, 1));
							int LastCode = Strings.Asc(tmp.Substring(tmpSearch.Length + Vindex, 1));
							if (!(SupportWords.IsExistsCode(FrontCode, CheckCode)) && !(SupportWords.IsExistsCode(LastCode, CheckCode)))
							{
								this.SelectionStart = System.Convert.ToInt32(FirstIndex + Vindex);
								this.SelectionLength = System.Convert.ToInt32(VbsKeyWords.FunCode[System.Convert.ToInt32(i)].FunName.Length);
								ChangeKeyWordColor(EnumChangeColor.EnumKeyWordColor);
								this.SelectionStart = System.Convert.ToInt32(FirstIndex + Vindex);
								this.SelectionLength = System.Convert.ToInt32(VbsKeyWords.FunCode[System.Convert.ToInt32(i)].FunName.Length);
								this.SelectedText = System.Convert.ToString(VbsKeyWords.FunCode[System.Convert.ToInt32(i)].FunName);
							}
						}
						if (Vindex + tmpSearch.Length + 1 < tmp.Length)
						{
							string tmpValue = tmp.Substring(Vindex + tmpSearch.Length + 1);
							int s = tmpValue.ToLower().IndexOf(tmpSearch);
							Vindex = s + Vindex + 1;
							if (s < 0)
							{
								break;
							}
						}
						else
						{
							break;
						}
					}
				}
			}
			catch
			{
			}
			this.SelectionStart = OldSelectionStart;
			SupportWords.AllowPaint(this.Handle);
			this.Refresh();
		}
		/// <summary>
		/// 获取当前行前一行最前面空格数量
		/// </summary>
		/// <param name="Index"></param>
		/// <returns></returns>
		/// <remarks></remarks>
		private int getFrontLineSpaceCount(int Index, string KeyWord = Constants.vbNullString, string EndW = Constants.vbNullString)
		{
			if (Index - 1 <= 0 | Index - 1 > this.Lines.Count() - 1)
			{
				return -1;
			}
			int WordCount1 = 0;
			int WordCount2 = 0;
			for (var i = Index - 1; i >= 0; i--)
			{
				if (string.IsNullOrEmpty(KeyWord))
				{
					string Tmp = this.Lines[i];
					int Result = getFrontSpaceCount(Tmp);
					if (Result >= 0)
					{
						return Result;
					}
				}
				else
				{
					string Tmp = this.Lines[i];
					if (Tmp.Trim().ToLower() == EndW.Trim().ToLower())
					{
						WordCount1++;
					}
					if (isExistsInKeyWord(Tmp, KeyWord))
					{
						if (WordCount1 == WordCount2)
						{
							int Result = getFrontSpaceCount(Tmp);
							return Result;
						}
						WordCount2++;
					}
				}
			}
			return -1;
		}
		/// <summary>
		/// 获取字符串左边空格数量
		/// </summary>
		/// <param name="Value"></param>
		/// <returns></returns>
		/// <remarks></remarks>
		private int getFrontSpaceCount(string Value)
		{
			string tmp = Value;
			if (!(string.IsNullOrEmpty(tmp)))
			{
				int Result = 0;
				for (var j = 0; j <= tmp.Length - 1; j++)
				{
					if (Strings.Asc(tmp.Substring(j, 1)) == 32)
					{
						Result++;
					}
					else
					{
						return Result;
					}
				}
				return Result;
			}
			else
			{
				return -1;
			}
		}
		/// <summary>
		/// 判断字符串中是否包含自定的关键词
		/// </summary>
		/// <param name="Value"></param>
		/// <param name="KeyWord"></param>
		/// <returns></returns>
		/// <remarks></remarks>
		private bool isExistsInKeyWord(string Value, string KeyWord)
		{
			string checkString = FormatSplitWordOnOneSpace(Value);
			KeyWord = KeyWord.Trim();
			if ((" " + checkString.ToLower() + " ").IndexOf(" " + KeyWord.ToLower() + " ") >= 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		private void CodeEditBox_DoubleClick(object sender, System.EventArgs e)
		{
			long OldSelectStart = this.SelectionStart;
			int Index = 0;
			for (var i = 0; i <= this.Lines.Count() - 1; i++)
			{
				CheckVbsLineCode(System.Convert.ToInt32(i));
				Index = System.Convert.ToInt32(this.GetFirstCharIndexFromLine(System.Convert.ToInt32(i)) + this.Lines[i].Length);
				CheckInputString(System.Convert.ToInt32(i), Index);
				CheckFunName(i, Index);
			}
		}
		
		private void CodeEditBox_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if ((int) e.KeyCode == 9)
			{
				this.SelectedText = Strings.Space(_TabCount);
			}
			e.Handled = true;
		}
		
		private void CodeEditBox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if (Strings.Asc(e.KeyChar) == 9)
			{
				e.Handled = true;
			}
		}
		
		private void CodeEditBox_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if ((int) e.KeyCode == 13)
			{
				CheckVbsLineCode(this.GetLineFromCharIndex(this.SelectionStart) - 1, this.SelectionStart, (System.Int32) e.KeyCode);
			}
		}
		
		private void CodeEditBox_TextChanged(object sender, System.EventArgs e)
		{
			string AppendString = "";
			try
			{
				//a = GetKeyboardLayout(0)
				if (this.SelectionLength > 0)
				{
					AppendString = this.SelectedText;
				}
				else
				{
					AppendString = this.Text.Substring(this.SelectionStart, 1);
				}
				if (Strings.Asc(AppendString) > 0)
				{
					int LineIndex = this.GetLineFromCharIndex(this.SelectionStart);
					long OldIndex = this.SelectionStart;
					CheckInputString(LineIndex, OldIndex);
					CheckFunName(LineIndex, OldIndex);
				}
			}
			catch
			{
			}
		}
		protected override void WndProc(ref System.Windows.Forms.Message m)
		{
			if (m.Msg == WM_PASTE)
			{
				for (var i = 0; i <= this.Lines.Count() - 1; i++)
				{
					CheckVbsLineCode(System.Convert.ToInt32(i));
				}
			}
			base.WndProc(ref m);
		}
		public void FreshString()
		{
			this.SelectionColor = this.ForeColor;
			int Index = 0;
			for (var i = 0; i <= this.Lines.Count() - 1; i++)
			{
				CheckVbsLineCode(System.Convert.ToInt32(i));
				Index = System.Convert.ToInt32(this.GetFirstCharIndexFromLine(System.Convert.ToInt32(i)) + this.Lines[i].Length);
				CheckInputString(System.Convert.ToInt32(i), Index);
				CheckFunName(i, Index);
			}
		}
	}
	
}
